const path = require("path");
const isDev = process.env.NODE_ENV === "development";
const devtool = isDev ? { devtool: "source-map" } : {}
/* impo */
module.exports = {
  mode: isDev ? "development" : "production",
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
    },
  },
  ...devtool,
  entry: "./src/index.js",
  target: "node",
  module: {
    rules: [
      {
        test: /\.js$/, // 正则表达式，匹配.js文件
        exclude: /node_modules/, // 排除node_modules目录
        use: {
          loader: 'babel-loader', // 使用babel-loader
          options: {
            presets: [
              '@babel/preset-env' // 转换ES6等新特性
            ]
          }
        }
      },
      {
        test: /\.(ttf|otf|eot|woff|woff2)$/,
        type: 'asset/resource',
        // 使用指定的loader处理字体
        generator: {
          filename: 'fonts/[hash][ext][query]'
        }
      },
    ]
  },
  output: {
    filename: "index.js",
    path: path.resolve(__dirname, "./dist"),
    publicPath: "/",
  },
};
